package com.skt.exception;

import lombok.Getter;

@Getter
public enum AuthErrorCode implements ErrorCode {

    // ========== 认证错误 (10xxx) ==========
    UNAUTHORIZED(10001, "未授权访问"),
    TOKEN_INVALID(10002, "Token无效或已过期"),
    TOKEN_EXPIRED(10003, "Token已过期"),
    TOKEN_MISSING(10004, "Token缺失"),
    AUTH_FAILED(10005, "认证失败"),
    ACCESS_DENIED(10006, "访问被拒绝"),
    USER_ID_INVALID(10007, "用户ID无效"),

    // ========== 登录相关 (101xx) ==========
    LOGIN_FAILED(10101, "登录失败"),
    USERNAME_PASSWORD_ERROR(10102, "用户名或密码错误"),
    ACCOUNT_LOCKED(10103, "账户已被锁定"),
    LOGIN_ATTEMPTS_EXCEEDED(10104, "登录尝试次数超限"),
    ACCOUNT_DISABLED(10105, "账户已被禁用"),
    IP_LOCKED(10106, "ip已被锁定"),
    LOGIN_OPERATION_FREQUENT(10206, "登录操作过于频繁，请稍后重试"),

    // ========== 注册相关 (102xx) ==========
    REGISTER_FAILED(10201, "注册失败"),
    USERNAME_EXISTS(10202, "用户名已存在"),
    EMAIL_EXISTS(10203, "邮箱已被注册"),
    PHONE_EXISTS(10204, "手机号已被注册"),
    INVITE_CODE_INVALID(10205, "邀请码无效"),
    REGISTER_OPERATION_FREQUENT(10206, "注册操作过于频繁，请稍后重试"),
    REGISTER_LOCK_ACQUIRE_FAILED(10207, "系统繁忙，请稍后重试"),
    REGISTER_CONCURRENT_OPERATION(10208, "检测到并发注册操作"),

    // 登出相关错误码
    LOGOUT_FAILED(10301, "登出失败"),
    LOGOUT_OPERATION_FREQUENT(10302, "操作频繁，请稍后重试"),
    USER_NOT_EXIST(10303, "用户不存在"),

    // ========== 刷新令牌相关 (104xx) ==========
    REFRESH_TOKEN_INVALID(10401, "刷新令牌无效"),
    REFRESH_TOKEN_EXPIRED(10402, "刷新令牌已过期"),
    REFRESH_TOKEN_REVOKED(10403, "刷新令牌已被撤销"),
    REFRESH_TOKEN_MISSING(10404, "刷新令牌缺失"),
    REFRESH_TOKEN_FORMAT_ERROR(10405, "刷新令牌格式错误"),
    REFRESH_OPERATION_FREQUENT(10406, "刷新操作过于频繁，请稍后重试"),
    REFRESH_TOKEN_BINDING_ERROR(10407, "刷新令牌与用户不匹配"),
    TOKEN_GENERATE_FAILED(10408, "令牌生成失败"),
    USER_NOT_LOGIN(10409, "用户未登录或会话已过期"),
    REFRESH_TOKEN_NOT_IN_SESSION(10410, "刷新令牌不在有效会话中"),

    // ========== 密码相关 (105xx) ==========
    PASSWORD_RESET_FAILED(10501, "密码重置失败"),
    PASSWORD_TOO_WEAK(10502, "密码强度不足"),
    PASSWORD_SAME_AS_OLD(10503, "新密码不能与旧密码相同"),
    PASSWORD_RESET_TOKEN_INVALID(10504, "密码重置令牌无效"),
    PASSWORD_RESET_TOKEN_EXPIRED(10505, "密码重置令牌已过期"),

    // ========== 新增：忘记密码相关 (1051x) ==========
    FORGOT_PASSWORD_FAILED(10511, "忘记密码请求失败"),
    FORGOT_PASSWORD_OPERATION_FREQUENT(10512, "忘记密码操作过于频繁，请稍后重试"),
    FORGOT_PASSWORD_LOCK_ACQUIRE_FAILED(10513, "系统繁忙，请稍后重试"),
    RESET_CREDENTIAL_GENERATE_FAILED(10514, "重置凭证生成失败"),
    NOTIFICATION_SEND_FAILED(10515, "通知发送失败"),
    USER_ACCOUNT_STATUS_INVALID(10516, "用户账户状态异常"),

    // ========== 新增：忘记密码参数验证相关 (10517-10520) ==========
    EMAIL_OR_PHONE_REQUIRED(10517, "邮箱或手机号至少提供一个"),
    EMAIL_AND_PHONE_MUTUAL_EXCLUSIVE(10518, "邮箱和手机号只能提供一个"),
    EMAIL_FORMAT_INVALID(10519, "邮箱格式无效"),
    PHONE_FORMAT_INVALID(10520, "手机号格式无效"),
    USER_NOT_FOUND_BY_CREDENTIALS(10521, "未找到匹配的用户账户"),

    // ========== 新增：风控相关 (1052x) ==========
    RISK_CONTROL_BLOCKED(10521, "操作被风控系统拦截"),
    IP_FREQUENCY_LIMITED(10522, "IP请求频率超限"),
    ACCOUNT_FREQUENCY_LIMITED(10523, "账户操作频率超限"),
    DEVICE_FINGERPRINT_INVALID(10524, "设备指纹异常"),

    // ========== 新增：分布式锁相关 (1053x) ==========
    DISTRIBUTED_LOCK_TIMEOUT(10531, "系统繁忙，请稍后重试"),
    CONCURRENT_OPERATION_DETECTED(10532, "检测到并发操作，请稍后重试"),

    // ========== 系统相关 (106xx) ==========
    SYSTEM_ERROR(10601, "系统异常，请稍后重试"),
    REDIS_OPERATION_FAILED(10602, "缓存操作失败"),
    DATABASE_OPERATION_FAILED(10603, "数据库操作失败"),
    NETWORK_ERROR(10604, "网络异常，请检查网络连接"),
    SERVICE_UNAVAILABLE(10605, "服务暂不可用，请稍后重试"),

    // ========== 身份/角色校验错误 (108xx) ==========
    REQUIRED_USER_ROLE(10801, "需要普通用户身份"),
    REQUIRED_MERCHANT_ROLE(10802, "需要商家身份"),
    REQUIRED_ADMIN_ROLE(10803, "需要管理员身份"),
    INVALID_USER_ROLE(10804, "用户角色无效或未设置"),
    ROLE_MISMATCH(10805, "当前用户角色与操作要求不匹配"),

    // ========== 权限相关 (109xx) ==========
    ROLE_NOT_FOUND(10901, "角色不存在"),
    ROLE_DISABLED(10902, "角色已被禁用"),
    PERMISSION_DENIED(10903, "权限不足");

    private final int code;
    private final String message;

    AuthErrorCode(int code, String message) {
        this.code = code;
        this.message = message;
    }
}